<?php
class AdminLeftNavWidget  extends CWidget{
    
	//输出字符串
	private $out = '';
    
    private $controller= '';
    
    private $action= '';

	public function init(){
        $this->controller = Yii::app()->controller->id;  
        $this->action = Yii::app()->controller->action->id; 
	}

	public function run(){
        $this->generateLeftNav();
		echo $this->out;
	}
    
    public function generateLeftNav(){
        //文章
        $blogClass = '';
        $blogChildShowCss = '';
        if($this->controller == 'blog'){
            $blogClass = 'current';
            $blogChildShowCss = 'display:block';
        }
        $blogList = Yii::app()->createUrl('/admin/blog');
        $blogCreate = Yii::app()->createUrl('/admin/blog/create');
        $blogCategory = Yii::app()->createUrl('/admin/blog/category');

        //资源
        $sourceClass = '';
        $sourceChildShowCss = '';
        if($this->controller == 'file'){
            $sourceClass = 'current';
            $sourceChildShowCss = 'display:block';
        }
        $sourceList = Yii::app()->createUrl('/admin/file');
        $sourceCreate = Yii::app()->createUrl('/admin/file/create');
        $sourceCategory = Yii::app()->createUrl('/admin/file/category');
        
        //链接
        $linkClass = '';
        $linkChildShowCss = '';
        if($this->controller == 'link'){
            $linkClass = 'current';
            $linkChildShowCss = 'display:block';
        }
        $linkList = Yii::app()->createUrl('/admin/link');
        $linkCreate = Yii::app()->createUrl('/admin/link/create');
        $linkCategory = Yii::app()->createUrl('/admin/link/category');

        //广告
        $adClass = '';
        $adChildShowCss = '';
        if($this->controller == 'ad'){
            $adClass = 'current';
            $adChildShowCss = 'display:block';
        }
        $adList = Yii::app()->createUrl('/admin/ad');
        $adCreate = Yii::app()->createUrl('/admin/ad/create');
        $adCategory = Yii::app()->createUrl('/admin/ad/category');

        //用户
        $userClass = '';
        $userChildShowCss = '';
        if($this->controller == 'user'){
            $userClass = 'current';
            $userChildShowCss = 'display:block';
        }
        $userList = Yii::app()->createUrl('/admin/user');
        $userCreate = Yii::app()->createUrl('/admin/user/create');
        $userCategory = Yii::app()->createUrl('/admin/user/category');

        //网站检测
        $detectClass = '';
        $detectChildShowCss = '';
        if($this->controller == 'default'){
            $detectClass = 'current';
            $detectChildShowCss = 'display:block';
        }
        $detectList = Yii::app()->createUrl('/admin/default');

        $this->out .= <<<OUT
                <div class='left-nav-downlist'>
                    <div class='downlist-title'>
                        <h1 class='downlist-title'>控制中心</h1>
                    </div>
                    <div class='downlist-box'>
                        <ul class='downlist-first-relation'>
                            <!-- 文章-->
                            <li>
                                <a class='{$blogClass}' href='#'>文章</a>
                                <ul style='{$blogChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='所有文章' href='{$blogList}'>所有文章</a>
                                    </li>
                                    <li>
                                        <a title='写文章' href='{$blogCreate}'>写文章</a>
                                    </li>
                                    <li>
                                        <a title='分类目录' href='{$blogCategory}'>分类目录</a>
                                    </li>

                                </ul>
                            </li>
                            <!-- 资源 -->
                            <li>
                                <a class='{$sourceClass}' href='#'>资源</a>
                                <ul style='{$sourceChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='所有资源' href='{$sourceList}'>所有资源</a>
                                    </li>
                                    <li>
                                        <a title='添加' href='{$sourceCreate}'>添加</a>
                                    </li>
                                    <li>
                                        <a title='分类目录' href='{$sourceCategory}'>分类目录</a>
                                    </li>

                                </ul>
                            </li>
                            <!-- 链接 -->
                            <li>
                                <a class='{$linkClass}' href='#'>链接</a>
                                <ul style='{$linkChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='所有链接' href='{$linkList}'>所有链接</a>
                                    </li>
                                    <li>
                                        <a title='添加' href='{$linkCreate}'>添加</a>
                                    </li>
                                    <li>
                                        <a title='分类目录' href='{$linkCategory}'>分类目录</a>
                                    </li>

                                </ul>
                            </li>
                            <!-- 广告 -->
                            <li>
                                <a class='{$adClass}' href='#'>广告</a>
                                <ul style='{$adChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='所有广告' href='{$adList}'>所有广告</a>
                                    </li>
                                    <li>
                                        <a title='添加' href='{$adCreate}'>添加</a>
                                    </li>
                                    <li>
                                        <a title='分类目录' href='{$adCategory}'>分类目录</a>
                                    </li>

                                </ul>
                            </li>
                            <!-- 用户 -->
                            <li>
                                <a class='{$userClass}' href='#'>用户</a>
                                <ul style='{$userChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='用户列表' href='{$userList}'>用户列表</a>
                                    </li>
                                    <li>
                                        <a title='添加' href='{$userCreate}'>添加</a>
                                    </li>
                                    <li>
                                        <a title='分类目录' href='{$userCategory}'>分类目录</a>
                                    </li>

                                </ul>
                            </li>
                            <!-- 网站性能检测 -->
                            <li>
                                <a class='{$detectClass}' href='#'>网站性能检测</a>
                                <ul style='{$detectChildShowCss}' class='downlist-second-relation'>
                                    <li>
                                        <a title='检测列表' href='{$detectList}'>检测列表</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
                
OUT;
        
    }
}


